<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>酒店辅助订购系统</title>
    <script th:src="@{js/jquery-3.4.1.min.js}"></script>
</head>
<body>
<td>
    <a th:href="'/user/add'"><button>添加酒店</button></a>
</td>
<table border="1">
    <thead>
    <!--<th>操作</th>-->
    <th>删除</th>
    <th>修改</th>
    <th>id</th>
    <th>name</th>
    <th>city</th>
    <th>province</th>
    <th>country</th>
    <th>star</th>
    <th>score</th>
    <th>landmark</th>
    <th>attrcation</th>
    <th>price</th>
    <th>hotel_tel</th>
    <th>breakfast</th>
    <th>address</th>
    </thead>
    <tbody >
    <tr th:each="user: ${users}" >
        <td th:attr="onclick=|deleteHotel(this,'${user.hotelId}')|"><button>删除</button>
        </td>
        <td>
            <a th:href="'/user/edit?hotel_id='+${user.hotelId}"><button>修改</button></a>
        </td>
        <td th:text="${user.getHotelId()}" th:attr="onclick=|deleteHotel(this,'${user.HotelId}')|"></td>
        <td th:text="${user.getHotelName()}"></td>
        <td th:text="${user.getCity()}"></td>
        <td th:text="${user.getProvince()}"></td>
        <td th:text="${user.getCountry()}"></td>
        <td th:text="${user.getStar()}"></td>
        <td th:text="${user.getScore()}"></td>
        <td th:text="${user.getLandmark()}"></td>
        <td th:text="${user.getAttraction()}"></td>
        <td th:text="${user.getPrice()}"></td>
        <td th:text="${user.getHotelTel()}"></td>
        <td th:text="${user.getBreakfast()}"></td>
        <td th:text="${user.getAddress()}"></td>
        <td></td>
    </tr>
    </tbody>
</table>
<script>
    function deleteHotel(elem,hotel_id) {
        $.ajax({
            url: "api/v1/user/delete?hotel_id="+hotel_id,
            method: "get",
            success: function (data) {
                if(data)
                {
                    $(elem).parent().hide();
                }else{
                    alert("No record deleted");
                }
            },
            error: function (data) {
                alert(data);
            }
        });
    }
    $(document).ready(function(){

    });
</script>
</body>
</html>